import { Component, OnInit } from '@angular/core';
import { parts, optionAuditStatus } from '../HuoMesstmp.model';
import { ApiService } from '../../../../providers/ApiPro.service';


@Component({
  selector: 'app-MessDriver',
  templateUrl: './MessDriver.component.html',
  styleUrls: ['./MessDriver.component.scss']
})
export class MessDriverComponent implements OnInit {
    public data = [];
    public total: number;
    public parts: parts = new parts();
    public pageIndex = 1;
    public options = [
      { value: 'A1', label: 'A1' },
      { value: 'A2', label: 'A2' },
      { value: 'A3', label: 'A3' },
      { value: 'B1', label: 'B1' },
      { value: 'B2', label: 'B2' },
      { value: 'C1', label: 'C1' },
      { value: 'C2', label: 'C2' },
      { value: 'C3', label: 'C3' },
      { value: 'C4', label: 'C4' },
    ];

   public optionAuditStatus = optionAuditStatus;
  constructor(
    private apiService: ApiService,
  ) { }

  ngOnInit() {
    this.loadAll();
  }


  loadAll(){
    let url = "finddrivers";
    //下面的if语句是因为组件的删除会有一个null值残留，影响get请求。
    if(!this.parts.driverName){
      delete this.parts.driverName;    
    }
    if(!this.parts.driverMobile){
      delete this.parts.driverMobile;    
    }
    if(!this.parts.driverAccount){
      delete this.parts.driverAccount;
    }
    if(!this.parts.driverType){
      delete this.parts.driverType;
    }
    if(!this.parts.auditStatus){
      delete this.parts.auditStatus;
    }
    this.apiService.get(url,this.parts)
      .then(res =>{
        this.total = res.totalCount;
        this.data = res.result;
      })
  }

  resetIndex(e) {
        this.parts.setPage(e);
        this.loadAll();
  }

}
